package com.hengxing.demo.io;

import org.junit.Test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author hengxing
 * @version 1.0
 * @project SocketDemoHx
 * @date 5/30/2023 14:13:59
 */
public class FileIO {
    public void writeToFile(List<String> ips) throws IOException {
        File file = new File("src/main/resources/ip.properties");
        FileOutputStream os = new FileOutputStream(file);
        int index = 0;
        for (String ip:
             ips) {
            String s = new String("controller.ip[" + index++ + "]=");
            os.write(s.getBytes());
            os.write(ip.getBytes());
            os.write("\n".getBytes());
        }
        os.write("controller.port=4660\n".getBytes());
        os.close();
    }

    @Test
    public void test01() throws IOException {
        FileIO io = new FileIO();
        ArrayList<String> list = new ArrayList<>();
        list.add("169.254.56.22");
        list.add("169.254.56.21");
        io.writeToFile(list);
    }

}
